// pages/doctorList/doctorList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentType: {},
    doctorList: []
  },

  onClick(event) {
    console.log("onClick", event);

    let doctorInfo = event.currentTarget.dataset.item;

    console.log("param doctorInfo", doctorInfo);

    wx.navigateTo({
      url: '/pages/department/doctor/doctor?doctorInfo=' + encodeURIComponent(JSON.stringify(doctorInfo))
    });
  },

  // 生命周期函数--监听页面初次渲染完成
  onLoad(options) {
    console.log("onLoad ", options);
    let doctorType = JSON.parse(decodeURIComponent(options.doctorType));
    this.setData({
      currentType: doctorType
    });
 
    console.log("this currentType", this.data.currentType);
    wx.setNavigationBarTitle({
      title: this.data.currentType.text,
    })

    var that = this;
    wx.cloud.callFunction({
      name: "get_doctor_info",
      data: {
        type: this.data.currentType.typeId
      },
      success: res => {
        console.log("get_doctor_info success", res);

        that.setData({
          doctorList: res.result.data
        });

        console.log("doctorList", that.data.doctorList);
      },
      fail: res => {
        console.log("get_doctor_info fail", res);
      }
    });
  },

  // 生命周期函数--监听页面初次渲染完成
  onReady() { },

  // 生命周期函数--监听页面显示
  onShow() { },

  // 生命周期函数--监听页面隐藏
  onHide() { },

  // 生命周期函数--监听页面卸载
  onUnload() { },

  // 页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh() { },

  // 页面上拉触底事件的处理函数
  onReachBottom() { },

  // 用户点击右上角分享
  onShareAppMessage() { }
})